/*
 * @Author: wangxiaojie
 * @LastEditors: wangxiaojie
 */
let { createStore } = require('./store')

const reducer = (state = { num: 100 }, action) => {
  switch (action.type) {
    case "clear":
      return { num: 0 };
    case "add":
      return { num: state.num + action.payload };
    default:
      return state;
  }
}

// dispatch 触发执行的函数
function handleDispatch () {
  console.log('dispatch触发')
}

const store = createStore(reducer)

store.effect(handleDispatch)

store.dispatch({
  type: 'clear'
})

console.log(store.getState().num)